/*
 *  classfile.h
 *
 *  Copyright (C) 2011  Jason<linux8192@gmail.com>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _CLASS_FILE_H_
#define _CLASS_FILE_H_

#include "type.h"
#include "constant_info.h"
#include "field_info.h"
#include "method_info.h"
#include "attribute_info.h"


/*
 * Access flags
 */
#define CLS_DESC_ACC_PUBLIC	0x0001
#define CLS_DESC_ACC_FINAL	0x0010
#define CLS_DESC_ACC_SUPER	0x0020
#define CLS_DESC_ACC_INTERFACE	0x0200
#define CLS_DESC_ACC_ABSTRACT	0x0400

/*
 * Class file descriptor
 */

typedef struct _class_file_desc {

	u4		magic;
	u2		minor_version;
	u2		major_version;

	u2		constant_pool_count;
	cp_info_t	**constant_pool;

	u2		access_flags;

	u2		this_class;
	u2		super_class;

	u2		interfaces_count;
	u2		*interfaces;

	u2		fields_count;
	field_info_t	*fields_info;

	u2		methods_count;
	method_info_t	*methods_info;

	u2		attribute_count;
	attr_t		*attributes;

} class_file_desc_t;


/*
 * Functions
 */

class_file_desc_t *parse_class_descriptor(const char *cls_buf, const int cls_buf_len);
void dump_class(class_file_desc_t *cls_desc);

#endif /* _CLASS_FILE_H_ */
